<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/information.png" alt="" /> <?php echo $heading_title; ?></h1>
      
    </div>
    <div class="content">
        <table class="list">
          <thead>
            <tr>
              <td  style="text-align: center;">ID</td>
              <td class="left">Name</td>
              <td class="left">Link</td>
              <td class="left">Desc</td>
              <!-- <td style="text-align: center;">Status</td> -->
              <td style="text-align: center;">Opration</td>
            </tr>
          </thead>
          <tbody>
            <?php if ($friends){
              foreach ($friends as $friend) {?>
                <tr>
                  <td style="text-align: center;"><?php echo $friend['id'];?></td>
                  <td class="left"><?php echo $friend['name'];?></td>
                  <td class="left"><a href="<?php echo $friend['link'];?>" target="_blank"><?php echo $friend['link'];?></a></td>
                  <td class="left"><?php echo $friend['description'];?></td>
                  <!-- <td style="text-align: center;"><?php if($friend['show']){?>cancel pass<?php }?></td> -->
                  <td style="text-align: center;"><?php if($friend['show']){?> <a id='change_<?php echo $friend['id'];?>' href='javascript:void(0)' onclick="change_s(<?php echo $friend['id'].','.abs($friend['show']-1)?>)"> cancel pass</a><?php }else{ ?><a id='change_<?php echo $friend['id'];?>' href='javascript:void(0)' onclick="change_s(<?php echo $friend['id'].','.abs($friend['show']-1)?>)">pass</a><?php }?>&nbsp;&nbsp;
                  <a href="javascript:void(0)" onclick="del(<?php echo $friend['id'];?>)">del</a>
                  </td>
                </tr>
              <?php } ?>
            <?php } ?>
           </tbody>
        </table>
      </form>
      <div class="pagination"><?php echo $pagination; ?></div>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
  function change_s(id,stat){
    $.ajax({
      url: 'index.php?route=web/friend/update&token=<?php echo $token; ?>',
      dataType: 'json',
      type:'post',
      data:{
        "id":id,
        "status":stat
      },
      success: function(json) {   
        if(json==1){
          if(stat==1){
            $('#change_'+id).html("<a id='change_'"+id+" href='javascript:void(0)' onclick='change_s("+id+",0)'>cancel pass</a>");
          }else{
            $('#change_'+id).html("<a id='change_'"+id+" href='javascript:void(0)' onclick='change_s("+id+",1)'>pass</a>");
          }

        }else{
          alert('UPDATE ERROR');
        }
      }
    });
  }
  function del(id){
    if(confirm("DELETE THIS FRIEND LINK?")){
      $.ajax({
      url: 'index.php?route=web/friend/del&token=<?php echo $token; ?>',
      dataType: 'json',
      type:'post',
      data:{
        "id":id
      },
      success: function(json) {   
        if(json==1){
            alert("DEL SUCCESS");
            window.location.reload();
        }else{
          alert("DEL ERROR")
        }

      }
    });
    }
  }
//--></script> 
<?php echo $footer; ?>